package cn.zwxky.android.staff.Jurisdiction.Operate;

import android.app.Fragment;
import android.content.Intent;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zgscwjm.lsfbbasetemplate.LsfbActivity;
import com.zgscwjm.lsfbbasetemplate.annotation.ContentView;
import com.zgscwjm.lsfbbasetemplate.annotation.OnClick;
import com.zgscwjm.lsfbbasetemplate.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

import cn.zwxky.android.staff.Follow.Arrange;
import cn.zwxky.android.staff.Jurisdiction.Marketplace.ReleaseTaskActivity;
import cn.zwxky.android.staff.R;
import cn.zwxky.android.staff.Utils.NoDoubleClickUtils;

/**
 * 经营部部项目审批页面
 * Created by Administrator on 2017/3/31 0031.
 */
@ContentView(R.layout.aty_task_approve)
public class OperateTaskApproveActivity extends LsfbActivity {

    /**
     * 项目任务按钮
     */
    @ViewInject(R.id.follow_btn1)
    private RelativeLayout follow_btn1;
    /**
     * 领导安排
     */
    @ViewInject(R.id.follow_btn2)
    private RelativeLayout follow_btn2;

    @ViewInject(R.id.follow_text1)
    private TextView follow_text1;

    @ViewInject(R.id.follow_text2)
    private TextView follow_text2;

    /**
     * 用于存储网络数据存储
     */
    private List<Fragment> fragments;

    /**
     * 项目审批
     */
    private OperateTaskApprove operateTaskApprove;

    /**
     * 领导安排
     */
    private Arrange arrange;


    @Override
    public void initView() {

    }

    @Override
    public void initEvent() {

    }

    /**
     * 点击事件
     *
     * @param view
     */
    @OnClick({R.id.follow_btn1, R.id.follow_btn2,R.id.fg_back,R.id.fg_add})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.follow_btn1:
                if (!NoDoubleClickUtils.isDoubleClick()) {
                    selectBtn(0);
                }
                break;
            case R.id.follow_btn2:
                if (!NoDoubleClickUtils.isDoubleClick()) {
                    selectBtn(1);
                }
                break;
            case R.id.fg_back:
                if (!NoDoubleClickUtils.isDoubleClick()) {
                    finish();
                }
                break;
            case R.id.fg_add:
               startActivity(new Intent(this,ReleaseTaskActivity.class));
                break;
        }
    }

    /**
     * 初始化Fragment
     */
    public void initFragments() {
        fragments = new ArrayList<>();
        operateTaskApprove = new OperateTaskApprove();
        arrange = new Arrange();
        fragments.add(operateTaskApprove);
        fragments.add(arrange);
        selectBtn(0);
    }

    /**
     * 选择fragment
     *
     * @param position
     */
    public void selectFragment(int position) {
        getFragmentManager().beginTransaction().replace(R.id.fragment_layout, fragments.get(position)).commit();
    }

    /**
     * 选择不同的fragment的样式改变
     *
     * @param position
     */
    public void selectBtn(int position) {
        switch (position) {
            case 0:
                follow_btn1.setBackground(getResources().getDrawable(R.drawable.btn_downline));
                follow_text1.setTextColor(getResources().getColor(R.color.theme_color));
                follow_text2.setTextColor(getResources().getColor(R.color.hint_color));
                follow_btn2.setBackground(getResources().getDrawable(R.drawable.btn_uncheck));
                selectFragment(position);
                break;
            case 1:
                follow_btn1.setBackground(getResources().getDrawable(R.drawable.btn_uncheck));
                follow_text1.setTextColor(getResources().getColor(R.color.hint_color));
                follow_text2.setTextColor(getResources().getColor(R.color.theme_color));
                follow_btn2.setBackground(getResources().getDrawable(R.drawable.btn_downline));
                selectFragment(position);
                break;
        }

    }

    @Override
    public void initData() {
        initFragments();
        selectFragment(0);
    }
}
